package com.glsc.ngateway.common.api.common.ex;

import lombok.ToString;

/**
 * @author zhouzp
 * @date 2020/5/29
 * AmProduct项目的业务异常类定义，一般用于Service做业务逻辑处理、数据校验等异常抛出
 */
@ToString(callSuper = true)
public class GatewayException extends RuntimeException {
    private int status;
    private String msg;
    private Throwable throwable;

    public GatewayException(int status, String msg, Throwable throwable) {
        super(msg);//父类初始化必须是第一条语句，并且设置msg为自定义的错误消息

        this.status = status;
        this.msg = msg;
        this.throwable = throwable;
    }

    public GatewayException() {}

    public static GatewayException error(String msg) {
        Throwable throwable=new Throwable(msg);
        return new GatewayException(Result.CODE_ERROR, msg, throwable);
    }
    public static GatewayException error(Integer code, String msg) {
        Throwable throwable = new Throwable(msg);
        return new GatewayException(code, msg, throwable);
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Throwable getThrowable() {
        return throwable;
    }

    public void setThrowable(Throwable throwable) {
        this.throwable = throwable;
    }
}
